package edu.nf.hotel.cityroomhoteldao.impl;

import edu.nf.hotel.cityroomhotel.CityRoomHotel;
import edu.nf.hotel.cityroomhoteldao.CityRoomHotelDao;
import edu.nf.hotel.util.ConnUtils;
import org.nf.db.util.SqlExecutor;
import org.nf.db.util.result.BeanListHandler;

import java.util.List;

/**
 * @Date 2023-06-29
 * @Author 带土
 */
public class CityRoomHotelDaoImpl implements CityRoomHotelDao {
    @Override
    public List<CityRoomHotel> getAllName(String cityName) {
        SqlExecutor executor = new SqlExecutor(ConnUtils.getConnection());
        BeanListHandler<CityRoomHotel> handler = new BeanListHandler<>(CityRoomHotel.class);
        String sql = "select city_name,room_image,hotel_name,hotel_location,room_price from city_type inner join " +
                "room_info on city_id=ht_id inner join hotel_information on city_id = c_id where city_name = ?" +
                " group by city_name,room_image,hotel_name,hotel_location,room_price";
        List<CityRoomHotel> list = executor.executeQuery(sql, handler,cityName);
        list.forEach(c -> System.out.println(c.getHotelName()+" "+c.getRoomImage()+" "
                +c.getHotelLocation()+" "+c.getRoomPrice()));
        return list;
    }
}
